﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Dqs_BLL;
using Dqs_DAL;
using Model;
using Sunny.UI;
using static Sunny.UI.ThunderDll;
namespace Dqs_UI
{
	public partial class frmUpdateTeacher : UIForm
	{
		public frmUpdateTeacher(int id)
		{
			InitializeComponent();
			this.Id = id;
		}

		int Id { get; set; }
		Teacher_BLL Teacher_BLL = new Teacher_BLL();

		private void frmUpdateTeacher_Load(object sender, EventArgs e)
		{
			TeacherInfo teacherInfo = Teacher_BLL.GetTeachers().Where(a => a.Id == Id).FirstOrDefault()!;
			txtStuNum.Text = teacherInfo.TeaNum;
			txtUserName.Text = teacherInfo.UserName;
			txtPwd.Text = teacherInfo.Password;
			txtFullName.Text = teacherInfo.FullName;
			txtPhone.Text = teacherInfo.Phone;
		}

		private void uiButton2_Click(object sender, EventArgs e)
		{
			frmUpdateTeacher_Load(this, e);
		}

		private void uiButton1_Click(object sender, EventArgs e)
		{
			TeacherInfo teacherInfo = new TeacherInfo();
			teacherInfo.Id = Id;
			teacherInfo.TeaNum = txtUserName.Text.Trim();
			teacherInfo.UserName = txtUserName.Text.Trim();
			teacherInfo.Password = txtPwd.Text.Trim();
			teacherInfo.FullName = txtFullName.Text.Trim();
			teacherInfo.Phone = txtPhone.Text.Trim();
			
			if (Teacher_BLL.UpdateTeacherInfoById(teacherInfo))
			{
				DialogResult = DialogResult.OK;
			}
			else
			{
				MessageBox.Show("请检查输入内容是否正确！");
			}
		}
	}
}
